package com.gopay.bis.service.bank.impl.fund;

import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.bis.manager.bank.fund.CiticFundManager;
import com.gopay.common.FundResult;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.fund.vo.PageData;
import com.gopay.common.domain.proccode.ProcCodeInfo;
import com.gopay.common.exception.GopayException;
import com.gopay.common.proccode.DicProcCodeService;
import com.gopay.common.util.DateUtils;
import com.gopay.remote.bank.FundInteractRemoteService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 中信基金服务
 * @CiticFundServiceImpl.java
 * @author wanggang
 * @2013-12-12 下午1:51:26 www.gopay.com.cn Inc.All rights reserved.
 */
public class CiticFundServiceImpl implements FundInteractRemoteService{

	@Resource(name = "citicFundManager")
	private CiticFundManager citicFundManager;

	@Resource(name = "dicProcCodeService")
	private DicProcCodeService dicProcCodeService;

	@Override
	public FundResult receive(PageData pageData) {
		FundResult result = new FundResult();
		result.setIsSuccess("F");
		try {
			boolean verify = citicFundManager.verify(pageData);
			if (verify){
				result.setIsSuccess("Y");
				result.setSerialNo(pageData.getString("serial_no"));
				result.setDepositTime(DateUtils.getCurrDate());
				result.setErrorCode("");
				result.setErrorMsg("");
			}
		} catch (GopayException e) {
			e.printStackTrace();
			BankLogUtils.printServiceImplExceptionLog(e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setErrorCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception ex) {
			BankLogUtils.printServiceImplExceptionLog(ex);
			result.setErrorCode(ProcCodeConstants.PROC_CODE_100E8519);
			result.setErrorMsg(ex.getMessage());
		}
		return result;
	}

	@Override
	public FundResult send(PageData pageData) {
		FundResult result = new FundResult();
		try {
			result = citicFundManager.send(pageData);
		} catch (GopayException e) {
			BankLogUtils.printServiceImplExceptionLog(e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setErrorCode(procCodeInfo!=null?procCodeInfo.getRespCode():e.getErrCode());
			result.setErrorMsg(procCodeInfo!=null?procCodeInfo.getMessage():e.getMessage());
		} catch (Exception ex) {
			BankLogUtils.printServiceImplExceptionLog(ex);
			result.setErrorCode(ProcCodeConstants.PROC_CODE_100E8519);
			result.setErrorMsg(ex.getMessage());
		}
		return result;
	}

}
